from aip import AipOcr
from config import *

from pytest_ui_ocrdemo.config import appId, apiKey, secretKey


# 调用文件识别
def readOcr(code_file):
    code = []
    # 新建一个AipOcr对象
    client = AipOcr(**{
        'appId': appId,
        'apiKey': apiKey,
        'secretKey': secretKey
    })
    with open(code_file, 'rb') as fp:
        image = fp.read()
        result = client.general(image)
        words_result = result["words_result"]
        if len(words_result) >0:
            code = words_result[0]["words"]
        print("识别的文字", code)
    return code

